package org.hit.burkun.extract;

import java.util.HashMap;
import java.util.Map;

import org.hit.burkun.entities.Entity;
import org.hit.burkun.entities.realtions.BaseRealtion;
import org.hit.burkun.entities.realtions.BaseRealtion.TYPE;
import org.hit.burkun.extract.FiledsToRealtionMapper.FILED;

/**
 * 获取relation ship的配置
 * 
 * @author burkun
 * 
 */
public class ExtractRelationConfigure {
	public static FiledsToRealtionMapper getGene2GeneFromStringDB() {
		String tbName = "protein_interactions";
		Map<FILED, String> fileds = new HashMap<>();
		// 可能存在多个id
		fileds.put(FILED.ENT1, "gene1_ids");
		fileds.put(FILED.ENT2, "gene2_ids");
		fileds.put(FILED.DBID, "primary_id");
		fileds.put(FILED.DESC, "mode");
		fileds.put(FILED.EVIDENCE_URLS, "soure_url");
		fileds.put(FILED.OTHER, "site_url");
		fileds.put(FILED.SCORE, "score");
		fileds.put(FILED.CALC_METHOD, "source"); // string
		FiledsToRealtionMapper fmapper = new FiledsToRealtionMapper(tbName,
				fileds, TYPE.GENE_GENE);
		return fmapper;
	}

	/**
	 * 依赖于三个视图：do_acc2acc, go_acc2acc, hp_acc2acc, 使用is_a 和 part of
	 * 
	 * @param type
	 * @return
	 */
	public static FiledsToRealtionMapper getOntologySelfRealtion(
			Entity.TYPE type) {
		String tbName;
		BaseRealtion.TYPE rtype = null;
		switch (type) {
		case DISEASE_ONTOLOGY:
			tbName = "do_acc2acc";
			rtype = TYPE.DO_DO;
			break;
		case GENE_ONTOLOGY:
			tbName = "go_acc2acc";
			rtype = TYPE.GO_GO;
			break;
		case HP_ONTOLOGY:
			tbName = "hp_acc2acc";
			rtype = TYPE.HP_HP;
			break;
		default:
			tbName = null;
			rtype = null;
		}
		if (tbName != null && rtype != null) {
			Map<FILED, String> fileds = new HashMap<>();
			// 可能存在多个id
			fileds.put(FILED.ENT1, "term1");
			fileds.put(FILED.ENT2, "term2");
			fileds.put(FILED.DESC, "rel_desc");
			fileds.put(FILED.SCORE, "score");
			FiledsToRealtionMapper fmapper = new FiledsToRealtionMapper(tbName,
					fileds, rtype);
			fmapper.setDirect(true);
			return fmapper;
		}
		return null;
	}

	/**
	 * Entity的初始化依赖与index_term
	 * 
	 * @param tbName
	 * @param type
	 * @return
	 */
	private static FiledsToRealtionMapper getOntology2GeneIDRealtionMapper(
			String tbName, BaseRealtion.TYPE type) {
		Map<org.hit.burkun.extract.FiledsToRealtionMapper.FILED, String> fileds = new HashMap<>();
		fileds.put(org.hit.burkun.extract.FiledsToRealtionMapper.FILED.ENT1,
				"term_acc"); // 依赖于index_term查询
		fileds.put(org.hit.burkun.extract.FiledsToRealtionMapper.FILED.ENT2,
				"gene_id");// 依赖于index_term查询
		fileds.put(FILED.DESC, "rel_desc");
		fileds.put(FILED.SCORE, "score");
		FiledsToRealtionMapper frm = new FiledsToRealtionMapper(tbName, fileds,
				type);
		frm.setDirect(false);
		return frm;
	}

	/**
	 * 获取Ontology相关的几个基因
	 */
	public static FiledsToRealtionMapper getDo2GeneRealtionMapper() {
		return getOntology2GeneIDRealtionMapper("do_geneid",
				BaseRealtion.TYPE.DO_GENE);
	}

	public static FiledsToRealtionMapper getGo2GeneRealtionMapper() {
		return getOntology2GeneIDRealtionMapper("go_geneid",
				BaseRealtion.TYPE.GO_GENE);
	}

	public static FiledsToRealtionMapper getHp2GeneRealtionMapper() {
		return getOntology2GeneIDRealtionMapper("hp_geneid",
				BaseRealtion.TYPE.HP_GENE);
	}

}
